﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using THenu.TinyHourseLib.DesignPattern.Behavioral_Patterns.Commond_Pattern.RealWorld;

namespace THenu.TinyHourseLib.DesignPattern.Behavioral_Patterns.Commond_Pattern
{
    class CommondPattern :IPatternDemonstrate
    {
        public void StructuralCode()
        {
            // Create receiver, command, and invoker 
            Receiver receiver = new Receiver(); 
            Command command = new ConcreteCommand(receiver); 
            Invoker invoker = new Invoker(); 
            // Set and execute command 
            invoker.SetCommand(command); 
            invoker.ExecuteCommand();
        }

        public string PatternDescription()
        {
            return "将一个请求封装为一个对象，从而使你可用不同的请求对客户进行参数化；对请求排队或记录请求日志，以及支持可撤消的操作。";
        }

        public void RealWorldExample()
        {
            // Create user and let her compute 
            User user = new User(); 
            user.Compute('+', 100); 
            user.Compute('-', 50); 
            user.Compute('*', 10);
            user.Compute('/', 2); 
            // Undo 4 commands 
            user.Undo(4); 
            // Redo 3 commands 
            user.Redo(3);
        }
    }
}
